package com.stgy.lease.web.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stgy.lease.common.exception.StgyException;
import com.stgy.lease.common.result.ResultCodeEnum;
import com.stgy.lease.model.domain.LeaseTerm;
import com.stgy.lease.model.domain.RoomInfo;
import com.stgy.lease.model.domain.RoomLeaseTerm;
import com.stgy.lease.web.api.mapper.LeaseTermMapper;
import com.stgy.lease.web.api.mapper.RoomLeaseTermMapper;
import com.stgy.lease.web.api.service.LeaseTermService;
import com.stgy.lease.web.api.service.RoomInfoService;
import com.stgy.lease.web.api.service.RoomLeaseTermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lingx
 * @description 针对表【lease_term(租期)】的数据库操作Service实现
 * @createDate 2024-08-28 11:00:29
 */
@Service
public class LeaseTermServiceImpl extends ServiceImpl<LeaseTermMapper, LeaseTerm>
        implements LeaseTermService {

    @Autowired
    private RoomLeaseTermService roomLeaseTermService;

    //根据房间id获取可选获取租期列表
    @Override
    public List<LeaseTerm> listByRoomId(Long id) {
        List<RoomLeaseTerm> roomLeaseTermList = roomLeaseTermService.list(Wrappers.lambdaUpdate(RoomLeaseTerm.class)
                .eq(RoomLeaseTerm::getRoomId, id));
        List<LeaseTerm> leaseTermList = roomLeaseTermList.stream().map(roomLeaseTerm -> {
            return this.getById(roomLeaseTerm.getLeaseTermId());
        }).collect(Collectors.toList());
        return leaseTermList;
    }
}




